import Redis from "ioredis";

export class Utils {
    static interface: Utils = null;
    static redisClient: Map<string, Redis> = new Map();
    constructor() {}
    static getInterface() {
        if (Utils.interface === null) {
            Utils.interface = new Utils()
        }
        return Utils.interface
    }
    set (name, options) {
        if (Utils.redisClient.has(name)) {
            throw new Error('redisClient连接名重复,请更换连接名')
        }
        Utils.redisClient.set(name, new Redis(options))
    }

    get (name) {
        return Utils.redisClient.get(name)
    }
    // 获取map的第一key
    getFirst(): string {
        return Utils.redisClient.keys().next().value
    }
}